# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Pavel Borzenkov <pavel@voidptr.ru>
# Contributor: aksr <aksr at t-com dot me>

pkgname=criu
pkgver=3.17.1
pkgrel=2
pkgdesc='Utilities to checkpoint and restore processes in userspace'
arch=('loong64' 'x86_64')
url='https://criu.org'
license=('GPL2')
depends=(
  'libbsd'
  'libnet'
  'libnl'
  'protobuf-c'
  'python-protobuf'
  'gnutls'
  'nftables'
)
makedepends=(
  'git'
  'xmlto'
  'asciidoc'
)
options=('!buildflags' '!lto')
_commit='d46f40f4ff0c724e0b9f0f8a2e8c043806897e94'
source=("$pkgname::git+https://github.com/checkpoint-restore/criu#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # FS#78218 - [criu] FTBFS with glibc 2.36+
  git cherry-pick --no-commit \
    1e6e826ffb7ac05f33fa123051c2fc2ddf0f68ea \
    4c86d6a7d54abb64fc5a15131f3351224e8c071b \
    517c0947050e63aac72f63a3bf373d76264723b9
}

build() {
  cd "$pkgname"

  make
}

package() {
  cd "$pkgname"

  make \
    DESTDIR="$pkgdir" \
    PREFIX=/usr \
    SBINDIR=/usr/bin \
    LIBDIR=/usr/lib \
    LIBEXECDIR=/usr/lib \
    install

  # remove empty directories
  rm -rf \
    "$pkgdir/usr/include/compel/common/asm" \
    "$pkgdir/var"
}
